define(function(){
	function index(){
		var cookieStr = $.cookie("MCLuserCookie");
		if(cookieStr){
			$("#top .ul1").css("display","none");
			$("#top .ul2").css("display","block");
		}else{
			$("#top .ul1").css("display","block");
			$("#top .ul2").css("display","none");
		}
		//退出按钮
		$(".quit").click(function(){
			$("#top .ul1").css("display","block");
			$("#top .ul2").css("display","none");s
		})
		function slider(){
			//轮播图
			//获取到图片
			this.li = document.getElementsByClassName("lis");
//			console.log(this.li);
			//记录当前下标
			this.indexA = 0;
			//获取按钮
			this.leftBtn = document.getElementsByClassName('leftBtn')[0];
			this.rightBtn = document.getElementsByClassName('RightBtn')[0];
			this.span = document.getElementsByClassName('num');
//			console.log(this.span);
			this.timer = null;
			this.init();
			this.sport();
			this.aotoPlay();
			//鼠标移入移出事件
			$('#lunbo').on({
				"mouseover" : function(){
					$('.btn').css("display",'block');
					$('.leftBtn').on({
						"mouseover" : function(){
							$(this).css("background-color",'red');
						},
						"mouseout" : function(){
							$(this).css('background-color','black');
						}
					})
					$('.RightBtn').on({
						"mouseover" : function(){
							$(this).css("background-color",'red');
						},
						"mouseout" : function(){
							$(this).css('background-color','black');
						}
					})
				},
				"mouseout" : function(){
					$('.btn').css("display",'none');
				}
			})
		}
		slider.prototype = {
			init : function(){
				for(var i = 0;i < this.li.length;i ++){
					this.li[i].style.display = 'none';
					this.span[i].style.backgroundColor = 'white';
				}
				this.li[this.indexA].style.display = 'block';
				this.span[this.indexA].style.backgroundColor = '#e1472f';
			},
			sport : function(){
				this.leftBtn.onclick = function(){
					this.indexA --;
					if(this.indexA < 0){
						this.indexA = this.li.length - 1;
					}
					this.init();
				}.bind(this)
				this.rightBtn.onclick = function(){
					this.indexA ++;
					if(this.indexA > this.li.length - 1){
						this.indexA = 0;
					}
					this.init();
				}.bind(this)
			},
			aotoPlay : function(){
				this.timer = setInterval(function(){
					this.indexA ++;
					this.indexA %= this.li.length;
					this.init();
				}.bind(this),4000)
			}
		}
		new slider();
		$('.second').on({
			"mouseover" : function(){
				$('.tel').animate({
						"left" : "-230px",
						"opacity" : '100'
					},500)
				},
			"mouseout" : function(){
				$('.tel').animate({
						"left" : "-300px",
						"opacity" : 0
					},500)
			}
			})
		//滚动事件
		$(window).scroll(function(){
			var $top = $(window).scrollTop();
			if($top >= 200){
					$('.returnTop').fadeIn(1000,'linear');
			}else{
				$('.returnTop').fadeOut(1000,'linear');
			}
			$('.returnTop').click(function(){
				$top = 0;
			})
		})
		//鼠标滑入事件
		$('.one').on({
			"mouseover" : function(){
				$(".one .images").stop();
				$('.one .images').animate({"left" : "153px"},400);
				$('.one .shuoming').css('background-color','#eeafce');
				$('.one .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$(".one .images").stop();
				$('.one .images').animate({"left" : "162px"},400);
				$('.one .shuoming').css('background-color','white');
				$('.one .shuoming .txt').css('color','#888');
			},
			"click" : function(){
				$('#tilt').css('display','block');
				$('.detail').show(1000);
			}
		})
		//关闭按钮
		$('.closeBtn').click(function(){
			$('.detail').hide(1000);
			$('#tilt').css('display','none');
			return false;
		})
		$('.two').on({
			"mouseover" : function(){
				$('.two .images').stop();
				$('.two .images').animate({"left" : "153px"},400);
				$('.two .shuoming').css('background-color','#eeafce');
				$('.two .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.two .images').stop();
				$('.two .images').animate({"left" : "162px"},400);
				$('.two .shuoming').css('background-color','white');
				$('.two .shuoming .txt').css('color','#888');
			}
		})
		$('.three').on({
			"mouseover" : function(){
				$('.three .images').stop();
				$('.three .images').animate({"left" : "153px"},400);
				$('.three .shuoming').css('background-color','#eeafce');
				$('.three .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.three .images').stop();
				$('.three .images').animate({"left" : "162px"},400);
				$('.three .shuoming').css('background-color','white');
				$('.three .shuoming .txt').css('color','#888');
			}
		})
		$('.four').on({
			"mouseover" : function(){
				$('.four .images').stop();
				$('.four .images').animate({"left" : "10px"},400);
				$('.four .shuoming').css('background-color','#eeafce');
				$('.four .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.four .images').stop();
				$('.four .images').animate({"left" : 0},400);
				$('.four .shuoming').css('background-color','white');
				$('.four .shuoming .txt').css('color','#888');
			}
		})
		$('.five').on({
			"mouseover" : function(){
				$('.five .images').stop();
				$('.five .images').animate({"left" : "10px"},400);
				$('.five .shuoming').css('background-color','#eeafce');
				$('.five .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.five .images').stop();
				$('.five .images').animate({"left" : 0},400);
				$('.five .shuoming').css('background-color','white');
				$('.five .shuoming .txt').css('color','#888');
			}
		})
		$('.six').on({
			"mouseover" : function(){
				$('.six .images').stop();
				$('.six .images').animate({"left" : "153px"},400);
				$('.six .shuoming').css('background-color','#eeafce');
				$('.six .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.six .images').stop();
				$('.six .images').animate({"left" : "162px"},400);
				$('.six .shuoming').css('background-color','white');
				$('.six .shuoming .txt').css('color','#888');
			}
		})
		$('.seven').on({
			"mouseover" : function(){
				$('.seven .images').stop();
				$('.seven .images').animate({"left" : "10px"},400);
				$('.seven .shuoming').css('background-color','#97c86c');
				$('.seven .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.seven .images').stop();
				$('.seven .images').animate({"left" : 0},400);
				$('.seven .shuoming').css('background-color','white');
				$('.seven .shuoming .txt').css('color','#888');
			}
		})
		$('.eight').on({
			"mouseover" : function(){
				$('.eight .images').stop();
				$('.eight .images').animate({"left" : "153px"},400);
				$('.eight .shuoming').css('background-color','#97c86c');
				$('.eight .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.eight .images').stop();
				$('.eight .images').animate({"left" : "162px"},400);
				$('.eight .shuoming').css('background-color','white');
				$('.eight .shuoming .txt').css('color','#888');
			}
		})
		$('.nine').on({
			"mouseover" : function(){
				$('.nine .images').stop();
				$('.nine .images').animate({"left" : "10px"},400);
				$('.nine .shuoming').css('background-color','#97c86c');
				$('.nine .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.nine .images').stop();
				$('.nine .images').animate({"left" : 0},400);
				$('.nine .shuoming').css('background-color','white');
				$('.nine .shuoming .txt').css('color','#888');
			}
		})
		$('.ten').on({
			"mouseover" : function(){
				$('.ten .images').stop();
				$('.ten .images').animate({"left" : "153px"},400);
				$('.ten .shuoming').css('background-color','#97c86c');
				$('.ten .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.ten .images').stop();
				$('.ten .images').animate({"left" : "162px"},400);
				$('.ten .shuoming').css('background-color','white');
				$('.ten .shuoming .txt').css('color','#888');
			}
		})
		$('.eleven').on({
			"mouseover" : function(){
				$('.eleven .images').stop();
				$('.eleven .images').animate({"left" : "10px"},400);
				$('.eleven .shuoming').css('background-color','#97c86c');
				$('.eleven .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.eleven .images').stop();
				$('.eleven .images').animate({"left" : 0},400);
				$('.eleven .shuoming').css('background-color','white');
				$('.eleven .shuoming .txt').css('color','#888');
			}
		})
		$('.twelven').on({
			"mouseover" : function(){
				$('.twelven .images').stop();
				$('.twelven .images').animate({"left" : "153px"},400);
				$('.twelven .shuoming').css('background-color','#97c86c');
				$('.twelven .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.twelven .images').stop();
				$('.twelven .images').animate({"left" : "162px"},400);
				$('.twelven .shuoming').css('background-color','white');
				$('.twelven .shuoming .txt').css('color','#888');
			}
		})
		$('.thirteen').on({
			"mouseover" : function(){
				$('.thirteen .images').stop();
				$('.thirteen .images').animate({"left" : "153px"},400);
				$('.thirteen .shuoming').css('background-color','#8ccedc');
				$('.thirteen .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.thirteen .images').stop();
				$('.thirteen .images').animate({"left" : "162px"},400);
				$('.thirteen .shuoming').css('background-color','white');
				$('.thirteen .shuoming .txt').css('color','#888');
			}
		})
		$('.fourteen').on({
			"mouseover" : function(){
				$('.fourteen .images').stop();
				$('.fourteen .images').animate({"left" : "153px"},400);
				$('.fourteen .shuoming').css('background-color','#8ccedc');
				$('.fourteen .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.fourteen .images').stop();
				$('.fourteen .images').animate({"left" : "162px"},400);
				$('.fourteen .shuoming').css('background-color','white');
				$('.fourteen .shuoming .txt').css('color','#888');
			}
		})
		$('.fifteen').on({
			"mouseover" : function(){
				$('.fifteen .images').stop();
				$('.fifteen .images').animate({"left" : "10px"},400);
				$('.fifteen .shuoming').css('background-color','#8ccedc');
				$('.fifteen .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.fifteen .images').stop();
				$('.fifteen .images').animate({"left" : 0},400);
				$('.fifteen .shuoming').css('background-color','white');
				$('.fifteen .shuoming .txt').css('color','#888');
			}
		})
		$('.sixteen').on({
			"mouseover" : function(){
				$('.sixteen .images').stop();
				$('.sixteen .images').animate({"left" : "10px"},400);
				$('.sixteen .shuoming').css('background-color','#8ccedc');
				$('.sixteen .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.sixteen .images').stop();
				$('.sixteen .images').animate({"left" : 0},400);
				$('.sixteen .shuoming').css('background-color','white');
				$('.sixteen .shuoming .txt').css('color','#888');
			}
		})
		$('.seventeen').on({
			"mouseover" : function(){
				$('.seventeen .images').stop();
				$('.seventeen .images').animate({"left" : "153px"},400);
				$('.seventeen .shuoming').css('background-color','#8ccedc');
				$('.seventeen .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.seventeen .images').stop();
				$('.seventeen .images').animate({"left" : "162px"},400);
				$('.seventeen .shuoming').css('background-color','white');
				$('.seventeen .shuoming .txt').css('color','#888');
			}
		})
		$('.eighteen').on({
			"mouseover" : function(){
				$('.eighteen .images').stop();
				$('.eighteen .images').animate({"left" : "153px"},400);
				$('.eighteen .shuoming').css('background-color','#8ccedc');
				$('.eighteen .shuoming .txt').css('color','white');
			},
			"mouseout" : function(){
				$('.eighteen .images').stop();
				$('.eighteen .images').animate({"left" : "162px"},400);
				$('.eighteen .shuoming').css('background-color','white');
				$('.eighteen .shuoming .txt').css('color','#888');
			}
		})
		$('.big1').on({
			"mouseover" : function(){
				$('.big1 .images').stop();
				$('.big1 .images').animate({"left" :"175px"},400);
			},
			"mouseout" : function(){
				$('.big1 .images').stop();
				$('.big1 .images').animate({"left" : "182px"},400);
			}
		})
		$('.big2').on({
			"mouseover" : function(){
				$('.big2 .images').stop();
				$('.big2 .images').animate({"left" : "175px"},400);
			},
			"mouseout" : function(){
				$('.big2 .images').stop();
				$('.big2 .images').animate({"left" : "182px"},400);
			}
		})
		$('.big3').on({
			"mouseover" : function(){
				$('.big3 .images').stop();
				$('.big3 .images').animate({"left" : "5px"},400);
			},
			"mouseout" : function(){
				$('.big3 .images').stop();
				$('.big3 .images').animate({"left" : 0},400);
			}
		})
		$('.big4').on({
			"mouseover" : function(){
				$('.big4 .images').stop();
				$('.big4 .images').animate({"left" : "5px"},400);
			},
			"mouseout" : function(){
				$('.big4 .images').stop();
				$('.big4 .images').animate({"left" : 0},400);
			}
		})
		var $num = 0;
		//添加购物车的点击事件
		var id = $('.one').attr("data_id");
		$('.add1').click(function(){
			$('#tilt2').css('display','block');
			$('.ready').animate({
				"top" : "600px"
			},400);
			$num ++;
			var src = $('.one .images img').attr('src');
			var name = $('.one .shuoming .title').html();
			var price = parseFloat($('.one .shuoming .price').html().slice(1));
			var cookieStr = $.cookie("article") ? $.cookie("article") : "";
			var cookieObj = convertcookieStrToCookieObj(cookieStr);
			 if(id in cookieObj){
			 	cookieObj[id].num += 1;
			 }else{
			 	console.log($num);
			 	cookieObj[id] = {
			 		"src" : src,
			 		"name" : name,
			 		"numbers" : "V15C0190-001",
			 		"num" : 1,
			 		"price" : price
			 	};
			}
//			console.log(cookieObj)
			cookieStr = convertObjToCarStr(cookieObj);
//			console.log(cookieStr);
			$.cookie("article",cookieStr,{expires : 7,path : "/"});
		})
		function objTostr(obj){
			var str = id + "," + obj.src + "," + obj.name + "," + obj.numbers +"," + obj.num + "," + obj.price;
			return str;
		}
		//关闭的点击事件
		$('.closeBtn2').click(function(){
			$('#tilt2').css('display','none');
			$('.ready').animate({"top" : "-300px"},10);
		})
	}
	function convertcookieStrToCookieObj(cookieStr){
		if(!cookieStr){
			return {};
		}
		var goods = cookieStr.split(":");
		var obj = {};
		for(var i = 0;i < goods.length;i ++){
			var data = goods[i].split(",");
			obj[data[0]] = {
				src : data[1],
				name : data[2],
				numbers : data[3],
				num : parseInt(data[4]),
				price : parseFloat(data[5])
			}
		}
		return obj;
	}
	function convertObjToCarStr(obj){
		var cookieStrs = "";
		for(var id in obj){
			if(cookieStrs){
				cookieStrs += ":";
			}
			cookieStrs += id + "," + obj[id].src + "," + obj[id].name + "," + obj[id].numbers + "," + obj[id].num + "," + obj[id].price;
		}
		return cookieStrs;
	}
	return {
		index : index
	}
})